from django import template
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.views.decorators.cache import cache_page
from mhlandscaping.apps.service.models import Service, Category
import settings

template.add_to_builtins('apps.service.templatetags.service')

@cache_page(settings.CACHE_LENGTH, key_prefix="services")
def services(request):
    try:
        categories = Category.objects.all().filter(active = True).order_by('name')
    except Category.DoesNotExist:
        pass
    
    return render_to_response('service/templates/services.html', 
                              {'categories': categories}, 
                              context_instance=RequestContext(request))
    
def service(request, slug_service):
    try:
        service = Service.objects.get(slug = slug_service)
    except Service.DoesNotExist:
        raise Http404
    
    return render_to_response('service/templates/service.html', 
                              {'service': service}, 
                              context_instance=RequestContext(request))